﻿using System;
using System.Collections.Specialized;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;

namespace T4MvcJs.RoutesHandler
{
    #region fakes
    internal class FakeRequest : HttpRequestBase
    {
        public override string ApplicationPath
        {
            get
            {
                return "/";
            }
        }
        public override Uri Url
        {
            get
            {
                return new Uri("http://localhost/");
            }
        }
        public override NameValueCollection ServerVariables
        {
            get
            {
                return new NameValueCollection();
            }
        }
    }
    internal class FakeResponse : HttpResponseBase
    {
        public override string ApplyAppPathModifier(string virtualPath)
        {
            return virtualPath;
        }
    }

    internal class FakeHttpContext : HttpContextBase
    {
        private readonly HttpRequestBase _request;
        private readonly HttpResponseBase _response;
        public FakeHttpContext()
        {
            _request = new FakeRequest();
            _response = new FakeResponse();
        }

        public override HttpRequestBase Request
        {
            get { return _request; }
        }
        public override HttpResponseBase Response
        {
            get
            {
                return _response;
            }
        }
    }
    #endregion

    internal static class UrlHelperFactory
    {
        public static UrlHelper CreateUrlHelper(RouteCollection routeCollection)
        {
            return new UrlHelper(new RequestContext(new FakeHttpContext(), new RouteData()), routeCollection);
        }
    }
}